#include "grabthread.h"

GrabThread::GrabThread() {}

GrabThread *GrabThread::getInstance()
{
    static GrabThread* obj = new GrabThread();
    return obj;
}

void GrabThread::run()
{
    int nRet = MV_OK;
    MV_FRAME_OUT frame = {0};

    while(true)
    {
        nRet = MV_CC_GetImageBuffer(handle, &frame, 1000);
        if (nRet != MV_OK)
        {
            qDebug() << "Failed to get image buffer!";
            QThread::sleep(1);
            continue;
        }
        qDebug() << frame.stFrameInfo.nWidth << frame.stFrameInfo.nHeight << frame.stFrameInfo.nFrameNum;
        MyImageProvider::getInstance()->image = QImage(frame.pBufAddr, frame.stFrameInfo.nWidth, frame.stFrameInfo.nHeight, QImage::Format_RGB888);
        emit refreshImage();
        MV_CC_FreeImageBuffer(handle, &frame);
    }
}
